package org.egdp.jclpvm.core.context;

import java.io.IOException;
import java.net.URI;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.context.support.AbstractRefreshableApplicationContext;

@Scope("singleton")
public class CLContext extends AbstractRefreshableApplicationContext implements ConfigurableApplicationContext{

	private static Log logger = LogFactory.getLog(CLContext.class);
	
	private SDKContext sdkContext;
	private ProcessorUnit preferredUnitType;
	private URI openclLibPath;
	
	@Override
	protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory)
			throws IOException, BeansException {
		// TODO Auto-generated method stub
		logger.debug("Loading bean definitions for " + this.toString());
	}

	/**
	 * @param sdkContext the sdkContext to set
	 */
	public void setSdkContext(SDKContext sdkContext) {
		this.sdkContext = sdkContext;
		logger.debug("Applying " + this.sdkContext.toString());
	}

	/**
	 * @return the sdkContext
	 */
	public SDKContext getSdkContext() {
		return sdkContext;
	}

	/**
	 * @param preferredUnitType the preferredUnitType to set
	 */
	public void setPreferredUnitType(ProcessorUnit preferredUnitType) {
		this.preferredUnitType = preferredUnitType;
		logger.debug("Setting Preferred " + this.preferredUnitType.toString());
	}

	/**
	 * @return the preferredUnitType
	 */
	public ProcessorUnit getPreferredUnitType() {
		return preferredUnitType;
	}

	/**
	 * @param openclLibPath the openclLibPath to set
	 */
	public URI getOpenclLibPath() {
		return openclLibPath;
	}

	/**
	 * @return the openclLibPath
	 */
	public void setOpenclLibPath(URI openclLibPath) {
		this.openclLibPath = openclLibPath;
		logger.debug("Setting SDK native lib path [" + this.openclLibPath.toString() + "]");
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "CLContext [" + sdkContext.toString() + ", openclLibPath=" + openclLibPath.toString()
				+ ", " + preferredUnitType.toString() + "]";
	}

}
